<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

interface MenuItem {
  id: string
  title: string
  icon: string
  path: string
}

const router = useRouter()
const activeTab = ref(0) // 0: 门诊, 1: 住院, 2: 综合
const activeBottomTab = ref(0)

// 门诊服务
const outpatientServices = ref<MenuItem[]>([
  {
    id: 'report',
    title: '门诊报告',
    icon: '📋',
    path: '/outpatient-report'
  },
  {
    id: 'waiting',
    title: '候诊查询',
    icon: '⏰',
    path: '/waiting-query'
  },
  {
    id: 'order',
    title: '自助开单',
    icon: '📝',
    path: '/self-service-order'
  },
  {
    id: 'medical',
    title: '医技预约',
    icon: '🔬',
    path: '/medical-appointment'
  },
  {
    id: 'followup',
    title: '我的复诊',
    icon: '🔄',
    path: '/follow-up'
  },
  {
    id: 'number',
    title: '自助取号',
    icon: '🎫',
    path: '/self-service-number'
  },
  {
    id: 'guide',
    title: '门诊导诊单',
    icon: '📄',
    path: '/outpatient-guide'
  },
  {
    id: 'invoice',
    title: '电子票据',
    icon: '🧾',
    path: '/electronic-invoice'
  }
])

// 住院服务（暂时使用门诊服务）
const inpatientServices = ref<MenuItem[]>([])

// 综合服务
const comprehensiveServices = ref<MenuItem[]>([
  {
    id: 'consignment',
    title: '代寄服务',
    icon: '📦',
    path: '/consignment'
  },
  {
    id: 'decoction',
    title: '中药代煎',
    icon: '🍵',
    path: '/decoction'
  },
  {
    id: 'price',
    title: '价目查询',
    icon: '💰',
    path: '/price'
  },
  {
    id: 'guide',
    title: '就医指南',
    icon: '📖',
    path: '/guide'
  },
  {
    id: 'survey',
    title: '满意度调查',
    icon: '⭐',
    path: '/survey'
  },
  {
    id: 'floor',
    title: '楼层分布',
    icon: '🏢',
    path: '/floor'
  }
])

// 当前显示的服务列表
const currentServices = ref<MenuItem[]>(outpatientServices.value)

const handleMenuClick = (item: MenuItem) => {
  router.push(item.path)
}

const handleAppointment = () => {
  router.push('/medical-appointment')
}

const handlePayment = () => {
  // 门诊缴费
  console.log('门诊缴费')
}

// 切换标签
const handleTabChange = (index: number) => {
  activeTab.value = index
  switch (index) {
    case 0: // 门诊
      currentServices.value = outpatientServices.value
      break
    case 1: // 住院
      currentServices.value = inpatientServices.value.length > 0 ? inpatientServices.value : outpatientServices.value
      break
    case 2: // 综合
      currentServices.value = comprehensiveServices.value
      break
    default:
      currentServices.value = outpatientServices.value
  }
}
</script>

<template>
  <div class="home-view">
    <!-- 顶部标题栏 -->
    <div class="header">
      <div class="header-content">
        <h1 class="title">智慧医院平台</h1>
        <div class="header-icons">
          <van-icon name="ellipsis" size="20" />
          <van-icon name="cross" size="20" />
        </div>
      </div>
    </div>

    <!-- 主横幅 -->
    <div class="banner">
      <div class="banner-content">
        <div class="banner-text">
          <h2>健康生活</h2>
          <h2>轻松简单</h2>
        </div>
        <div class="banner-icons">
          <span class="icon">💉</span>
          <span class="icon">🛒</span>
          <span class="icon">👨‍⚕️</span>
        </div>
      </div>
    </div>

    <!-- 快速访问按钮 -->
    <div class="quick-access">
      <div class="quick-btn appointment-btn" @click="handleAppointment">
        <van-icon name="calendar-o" size="28" color="#fff" />
        <div class="btn-text">
          <div class="btn-title">门诊挂号</div>
          <div class="btn-subtitle">便捷预约挂号</div>
        </div>
      </div>
      <div class="quick-btn payment-btn" @click="handlePayment">
        <van-icon name="gold-coin-o" size="28" color="#fff" />
        <div class="btn-text">
          <div class="btn-title">门诊缴费</div>
          <div class="btn-subtitle">便捷预约挂号</div>
        </div>
      </div>
    </div>

    <!-- 公告栏 -->
    <div class="notice-section">
      <van-notice-bar
        left-icon="volume-o"
        text="智慧医院上线啦,手机也能问诊医..."
        color="#1989fa"
        background="#ecf9ff"
      />
    </div>

    <!-- 标签页 -->
    <div class="tabs-section">
      <van-tabs v-model:active="activeTab" class="custom-tabs" @change="handleTabChange">
        <van-tab title="门诊"></van-tab>
        <van-tab title="住院"></van-tab>
        <van-tab title="综合"></van-tab>
      </van-tabs>
      <span class="more-link">更多</span>
    </div>

    <!-- 服务网格 -->
    <div class="menu-section">
      <van-grid :column-num="activeTab === 2 ? 3 : 4" :border="false" class="service-grid">
        <van-grid-item
          v-for="item in currentServices"
          :key="item.id"
          :text="item.title"
          class="menu-item"
          @click="handleMenuClick(item)"
        >
          <template #icon>
            <div class="menu-icon">{{ item.icon }}</div>
          </template>
        </van-grid-item>
      </van-grid>
    </div>

    <!-- 健康资讯 -->
    <div class="health-info">
      <div class="info-content" @click="() => router.push('/health-column')">
        <div class="info-title">健康资讯</div>
        <div class="info-item">
          <div class="info-text">世界糖尿病日,应该注意什么</div>
        </div>
      </div>
      <van-button 
        class="customer-service-btn" 
        round 
        type="primary" 
        size="small"
        @click.stop="() => {}"
      >
        智能客服
      </van-button>
    </div>

    <!-- 底部导航栏 -->
    <van-tabbar v-model="activeBottomTab" fixed placeholder>
      <van-tabbar-item icon="home-o" to="/">诊疗首页</van-tabbar-item>
      <van-tabbar-item icon="wap-nav">微官网</van-tabbar-item>
      <van-tabbar-item icon="chat-o">消息中心</van-tabbar-item>
      <van-tabbar-item icon="user-o">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<style scoped>
.home-view {
  width: 100%;
  min-height: 100vh;
  background-color: #f7f8fa;
  padding-bottom: 50px;
}

/* 顶部标题栏 */
.header {
  background-color: #fff;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title {
  font-size: 18px;
  font-weight: bold;
  color: #323233;
  margin: 0;
}

.header-icons {
  display: flex;
  gap: 16px;
}

/* 主横幅 */
.banner {
  background: linear-gradient(135deg, #7bd89c 0%, #6bb8e8 100%);
  margin: 12px 16px;
  border-radius: 12px;
  padding: 24px 20px;
  height: 140px;
}

.banner-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.banner-text h2 {
  color: #fff;
  font-size: 28px;
  font-weight: bold;
  margin: 0;
  line-height: 1.2;
}

.banner-icons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.banner-icons .icon {
  font-size: 32px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 快速访问按钮 */
.quick-access {
  display: flex;
  gap: 12px;
  padding: 0 16px;
  margin-bottom: 12px;
}

.quick-btn {
  flex: 1;
  height: 80px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: transform 0.2s;
}

.quick-btn:active {
  transform: scale(0.98);
}

.appointment-btn {
  background: linear-gradient(135deg, #1989fa 0%, #0d7fe8 100%);
}

.payment-btn {
  background: linear-gradient(135deg, #07c160 0%, #06ae56 100%);
}

.btn-text {
  margin-top: 8px;
  text-align: center;
  color: #fff;
}

.btn-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 4px;
}

.btn-subtitle {
  font-size: 12px;
  opacity: 0.9;
}

/* 公告栏 */
.notice-section {
  margin: 0 16px 12px;
}

/* 标签页 */
.tabs-section {
  background-color: #fff;
  margin: 0 16px 12px;
  border-radius: 8px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.more-link {
  font-size: 14px;
  color: #969799;
  margin-left: 12px;
}

/* 服务网格 */
.menu-section {
  background-color: #fff;
  margin: 0 16px 12px;
  border-radius: 8px;
  padding: 16px 0;
}

.service-grid {
  padding: 0;
}

.menu-item {
  padding: 12px 8px;
}

.menu-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

:deep(.van-grid-item__text) {
  font-size: 14px;
  color: #323233;
  margin-top: 4px;
}

:deep(.van-grid-item__content) {
  padding: 0;
  flex-direction: column;
}

:deep(.van-grid-item__content--center) {
  align-items: center;
  justify-content: center;
}

/* 健康资讯 */
.health-info {
  background-color: #fff;
  margin: 0 16px;
  border-radius: 8px;
  padding: 16px;
  position: relative;
}

.info-content {
  cursor: pointer;
  flex: 1;
  padding-right: 80px;
}

.info-title {
  font-size: 16px;
  font-weight: bold;
  color: #323233;
  margin-bottom: 12px;
}

.info-item {
  padding: 8px 0;
}

.info-text {
  font-size: 14px;
  color: #646566;
  line-height: 1.5;
}

.customer-service-btn {
  position: absolute;
  right: 16px;
  bottom: 16px;
}

/* 标签页样式 */
:deep(.van-tabs__wrap) {
  padding: 0;
}

:deep(.van-tab) {
  font-size: 15px;
  color: #969799;
}

:deep(.van-tab--active) {
  color: #1989fa;
  font-weight: bold;
}

:deep(.van-tabs__line) {
  background-color: #1989fa;
}
</style>
